﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace ComicsEditor
{
    public class ColorRect : PageObject
    {
        public Rectangle Rectangle;
        public Color Body;
        public Color Border;
        public float BorderWidth;

        internal bool Strict = false;
        private Pen pen = null;

        public ColorRect(Page Page, Rectangle Rectangle, Color Body) : this(Page, Rectangle, Body, Color.Empty, 0f)
        {
        }

        public ColorRect(Page Page, Rectangle Rectangle, Color Border, float BorderWidth) : this(Page, Rectangle, Color.Empty, Border, BorderWidth)
        {
        }

        public ColorRect(Page Page, Rectangle Rectangle, Color Body, Color Border, float BorderWidth) : base(Page)
        {
            this.Rectangle = Rectangle;
            this.Body = Body;
            this.Border = Border;
            this.BorderWidth = BorderWidth;

            if (Border != Color.Empty)
            {
                pen = new Pen(Border);
                pen.Width = BorderWidth;
            }
        }

        public override void Draw(Graphics Graphics)
        {
            RectangleF rectF = new RectangleF(Page.Transform(Rectangle.Location), Page.Transform(new Size(Rectangle.Width - 1, Rectangle.Height - 1)));
            if (Body != Color.Empty)
                Graphics.FillRectangle(new SolidBrush(Body), rectF);
            if (pen != null)
            {
                if (Strict)
                {
                    Rectangle rect = new Rectangle((int)rectF.X, (int)rectF.Y, (int)rectF.Width, (int)rectF.Height);
                    Graphics.DrawRectangle(pen, rect);
                }
                else
                    Graphics.DrawRectangle(pen, rectF.X, rectF.Y, rectF.Width, rectF.Height);
            }
        }
    }
}
